import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
// import VueRouter from 'unplugin-vue-router/vite'
import VueMacros from 'unplugin-vue-macros/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  ElementPlusResolver,
} from 'unplugin-vue-components/resolvers'
import {ComponentResolver} from "unplugin-vue-components";


// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vueDevTools(),
    VueMacros({
      plugins: {
        vue: vue(),
        vueJsx: vueJsx(), // 如有需要
        // vueRouter: VueRouter({ // 如有需要
        //   extensions: ['.vue', '.setup.tsx']
        // })
      },
    }),
    Components({
      dirs: ['src/components'],
      extensions: ['vue'],
      resolvers: [
        //  Element Plus 组件自动导入
        ElementPlusResolver({
          // 如果需要自动导入图标组件
          importStyle: 'css',
          ssr: false, // 如果是SSR项目需要设置为true
          directives: true, // 启用指令自动导入
          version: "2.9.3", // 指定Element Plus版本
        }),
        // 自定义图标组件
        (name: string) => {
          if (name.startsWith('Icon')) {
            return { name: name.slice(4), from: '@element-plus/icons-vue' }
          }
        }
      ],
      dts: 'src/components.d.ts',
    }),
    AutoImport({
      eslintrc: {
        enabled: false,
        filepath: fileURLToPath(
            new URL('./.eslintrc-auto-import.json', import.meta.url)
        ),
        globalsPropValue: true
      },
      dts: 'src/auto-imports.d.ts',
      imports: [
        'vue',
        {
          'vue-request': ['useRequest'],
          // '@/hooks': ['useMessage', 'useDict', 'usePageTable', 'useDialog', 'useLoading', 'useRouter', 'useRoute']
        }
      ]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
